#include "traversee.h"

#include <sstream>

using namespace std;


// CONSTRUCTEURS
Traversee::Traversee()
{
}

Traversee::Traversee(int id, Port* portO, Port* portD)
{
    idTraversee = id;
    portOrigine = portO;
    portDestination = portD;
}

Traversee::~Traversee()
{
}

// GETTERS
int Traversee::getIdTraversee()
{
    return idTraversee;
}

Port* Traversee::getPortOrigine()
{
    return portOrigine;
}

Port* Traversee::getPortDestination()
{
    return portDestination;
}

/*Trajet* Traversee::getListEscales()
{
    return listEscales;
}*/

// SETTERS
void Traversee::setIdTraversee(int id)
{
    idTraversee = id;
}

void Traversee::setPortOrigine(Port* portO)
{
    portOrigine = portO;
}

void Traversee::setPortDestination(Port* portD)
{
    portDestination = portD;
}

// OPERATIONS SUR LES LISTES
void Traversee::AjouterEscale(Trajet *traj)
{
    if(1==1)
    {
        listEscales.push_back(traj);
    }
    else
    {
        cout<<"La liste ne peut pas contenir de trajet supplementaire.";
    }

}


string Traversee::AfficherListEscales()
{
    string result = "";
    list<Trajet*>::iterator it;
    for(it = listEscales.begin();it != listEscales.end();it++)
    {
        string chaine;
        std::ostringstream oss;
        oss << (*it)->getIdTrajet();
        chaine = oss.str();
        result = result+chaine+",";
    }
    return result;
}

bool Traversee::isTrajetCourant()
{
    struct tm Today;
    time_t maintenant;

    time(&maintenant);
    Today = *localtime(&maintenant);
    /*cout<<"  #  "<<timeDepart.tm_year+2000<<" - "<<Today.tm_year+1900<<endl;
    cout<<"  #  "<<timeDepart.tm_mon<<" - "<<Today.tm_mon+1<<endl;
    cout<<"  #  "<<timeDepart.tm_mday<<" - "<<Today.tm_mday<<endl;
    cout<<"  #  "<<timeDepart.tm_hour<<" - "<<Today.tm_hour<<endl;
    cout<<"  #  "<<timeDepart.tm_min<<" - "<<Today.tm_min<<endl;*/
    if(listEscales.front()->getTimeDepart().tm_year+2000 > Today.tm_year+1900)
    {
        return true;
    }
    else if(listEscales.front()->getTimeDepart().tm_year+2000 == Today.tm_year+1900)
    {
        if(listEscales.front()->getTimeDepart().tm_mon > Today.tm_mon+1)
        {
            return true;
        }
        else if(listEscales.front()->getTimeDepart().tm_mon == Today.tm_mon+1)
        {
            if(listEscales.front()->getTimeDepart().tm_mday > Today.tm_mday)
            {
                return true;
            }
            else if(listEscales.front()->getTimeDepart().tm_mday == Today.tm_mday)
            {
                if(listEscales.front()->getTimeDepart().tm_hour > Today.tm_hour)
                {
                    return true;
                }
                else if(listEscales.front()->getTimeDepart().tm_hour == Today.tm_hour)
                {
                    if(listEscales.front()->getTimeDepart().tm_min >= Today.tm_min)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
    }
    return false;
}
